﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Microsoft Corp." file="CreateSqlAzureServerCommand.cs">
//   All rights reserved. See License.txt in the project root for license information.
// </copyright>
// 
// --------------------------------------------------------------------------------------------------------------------
namespace AzureManagement.SqlAzureCommands
{
    using System;

    using AzureManagement.AzureCommands;
    using AzureManagement.SqlAzureDataContracts;

    using Common;

    using RestClient;

    public class CreateSqlAzureServerCommand : AzureManagementCommand
    {
        private readonly CreateSqlAzureServer server;

        public CreateSqlAzureServerCommand(IAzureServiceContext serviceContext, CreateSqlAzureServer server)
            : base(serviceContext)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server", "Sql Azure Server details must not be null.");
            }

            this.server = server;
        }

        protected override RequestContext GetRequestContext()
        {
            return this.CreatePostOperationRequestContext();
        }

        protected override string FormatPath(IAzureServiceContext azureServiceContext)
        {
            return string.Format("{0}/servers", azureServiceContext.SubscriptionId);
        }

        protected override string FormatBody()
        {
            return XmlHelper.Serialize(this.server);
        }
    }
}